﻿<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/common/taglibs.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
<base href="${ctx }/admin/" />

<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="own/images/favicon.ico">
<link rel="Shortcut Icon" href="own/images/favicon.ico" />
<link href="own/css/index.css" rel="stylesheet">
<title>后台登录 - 用户管理</title>

<style type="text/css">
	.usernameTip, .passwordTip {
		color: red;
		font-size: 12px;
	}
</style>

</head>

<body>
    <div class="container">
        <div class="con"> 
            <h2>${title }</h2>
            <div class="main">
                <form id="loginForm" class="form form-horizontal" action="${ctx}/admin/user/login" method="post" target="_top">
                  <div class="text">
                    <div class="formControls col-xs-8">
                      <input id="username" name="username" type="text" class="input-text size-L" onblur="check('username')" placeholder="帐号" >
                    </div>
                  </div>
                  <div class="text2">
                    <div class="formControls col-xs-8">
                      <input id="password" name="password" type="password" placeholder="密码" onblur="check('password');" class="input-text size-L">
                    </div>
                  </div>
                  <div class="text3" >
                    <div class="formControls col-xs-8 col-xs-offset-3">
                          <input onblur="jsonCheckCode('inputcode');" name="verification" id="inputcode" class="input-text" type="text" placeholder="验证码"  onclick="if(this.value=='验证码:'){this.value='';}" value="验证码:" />
                        <img src="${ctx}/admin/user/createcode" class="code" id="code" onclick="var d = new Date();this.src='${ctx}/admin/user/createcode?t='+d.getTime();"> 
                    </div>
                  </div>
                  <div class="text4">看不清楚可以点击验证码换一张</div>
                    <div class="text5">
                        <a href="javascript:void(0);">
                        <input type="button" id="login_btn" class="btn" onclick="login('username','password','loginForm','inputcode');" value="登&nbsp;录" />
                        </a>
                    </div>
                   <div style="text-align: center;">
                    <span class="usernameTip passwordTip" id="nameInfo" ></span>
                   </div>
                </form>
          </div>
        </div>
	    <div class="footer">${copyright }${address} </div>
    </div>
    <script type="text/javascript" src="h-ui/lib/jquery/1.9.1/jquery.min.js"></script>

	<script type="text/javascript">
	
		$(document).ready(function(){
			$("#inputcode").keydown(function(e){
				var curkey = e.which; 
				if(curkey == 13){ 
					$("#login_btn").click();
					return false; 
				}
			});
			
			$("#nameInfo").text('${msg}');
		});
	   
		function refreshCode(){
			var d = new Date();
			$('#code').prop('src', '${ctx}/admin/user/createcode?t='+d.getTime());
		}
	
		function check(str) {
			var zhi = $("#" + str).val();
			if (zhi == null || $.trim(zhi) == "") {
				if (str == "username") {
                    $("#nameInfo").text("用户名不能为空");
				} else {
                    $("#nameInfo").text("密码不能为空");
				}

				return false;
			} else {
                $("#nameInfo").empty();
				return true;
			}
		}

		function login(usn, psw, formid, codeId) {
			var bt1 = check(usn);
            if(!bt1){
                return;
            }
            var bt2 = check(psw);
            if(!bt2){
                return;
            }
            var bt3 = jsonCheckCode(codeId);
            if(!bt3){
                return;
            }
            $("#" + formid).submit();
		}
		
		function jsonCheckCode(codeId) {
			var verif = $('#' + codeId).val();
			var flag = false;
			$.ajax({
				async : false,
				type : "post",
				data : {
					verification : verif
				},
				url : "${ctx}/admin/user/checkcode",
				success : function(json) {
					if (json == 'fail') {
						$("#nameInfo").text("验证码输入错误");
						refreshCode();
					} else if (json == 'error') {
						$("#nameInfo").text("系统错误，请重试！");
                        refreshCode();
					} else {
						$("#nameInfo").text("");
						flag = true;
					}
				}
			});
			return flag;
		}
	</script>
</body>
</html>
